containerd 高级命令行工具 nerdctl
1.nerdctl简介
安装containerd后是使用 ctr
操作管理 containerd 镜像容器,但是大家都习惯了使用 docker cli,ctr
使用起来可能还是不太顺手,为了能够让大家更好的转到 containerd 上面来,社区提供了一个新的命令行工具:nerdctl。nerdctl 是一个与 docker cli 风格兼容的 containerd 客户端工具,而且直接兼容 docker compose 的语法的,这就大大提高了直接将 containerd 作为本地开发、测试或者单机容器部署使用的效率。
2.nerdctl安装
2.1 未安装containerd
如果没有安装 containerd,则可以下载 nerdctl-full-<VERSION>-linux-amd64.tar.gz 包进行安装,并且nerdctl-full这个包是与containerd版本一一对应的,即containerd发布一个版本后,nerdctl-full也随即发布一个版本,虽然2者版本号不一致,但是是互相对应的
2.1.1 下载包
export NERDCTL_VERSION=0.16.1
wget https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-full-${NERDCTL_VERSION}-linux-amd64.tar.gz
2.1.2 查看包内容
# 查看包内容,解压缩后是bin lib libexec share 4个目录
$ tar -tf nerdctl-full-${NERDCTL_VERSION}-linux-amd64.tar.gz
bin/
bin/buildctl
bin/buildkitd
bin/containerd
bin/containerd-fuse-overlayfs-grpc
bin/containerd-rootless-setuptool.sh
bin/containerd-rootless.sh
bin/containerd-shim-runc-v2
bin/containerd-stargz-grpc
bin/ctd-decoder
bin/ctr
bin/ctr-enc
bin/ctr-remote
bin/fuse-overlayfs
bin/ipfs
bin/nerdctl
bin/rootlessctl
bin/rootlesskit
bin/runc
bin/slirp4netns
lib/
lib/systemd/
lib/systemd/system/
lib/systemd/system/buildkit.service
lib/systemd/system/containerd.service
lib/systemd/system/stargz-snapshotter.service
libexec/
libexec/cni/
libexec/cni/bandwidth
libexec/cni/bridge
libexec/cni/dhcp
libexec/cni/firewall
libexec/cni/host-device
libexec/cni/host-local
libexec/cni/ipvlan
libexec/cni/isolation
libexec/cni/loopback
libexec/cni/macvlan
libexec/cni/portmap
libexec/cni/ptp
libexec/cni/sbr
libexec/cni/static
libexec/cni/tuning
libexec/cni/vlan
libexec/cni/vrf
share/
share/doc/
share/doc/nerdctl/
share/doc/nerdctl/README.md
share/doc/nerdctl/docs/
share/doc/nerdctl/docs/cni.md
share/doc/nerdctl/docs/compose.md
share/doc/nerdctl/docs/config.md
share/doc/nerdctl/docs/cosign.md
share/doc/nerdctl/docs/dir.md
share/doc/nerdctl/docs/experimental.md
share/doc/nerdctl/docs/faq.md
share/doc/nerdctl/docs/freebsd.md
share/doc/nerdctl/docs/gpu.md
share/doc/nerdctl/docs/ipfs.md
share/doc/nerdctl/docs/multi-platform.md
share/doc/nerdctl/docs/ocicrypt.md
share/doc/nerdctl/docs/registry.md
share/doc/nerdctl/docs/rootless.md
share/doc/nerdctl/docs/stargz.md
share/doc/nerdctl-full/
share/doc/nerdctl-full/README.md
share/doc/nerdctl-full/SHA256SUMS
2.1.3 解压缩包
解压缩包至 /usr/local
下,buildctl
、 buildkitd
、containerd
、ctr
、nerdctl
、runc
等命令就会全部包含,同时使用systemd管理buildkit文件buildkit.service
、使用systemd管理containerd文件 containerd.service
也会包含
tar xf nerdctl-full-${NERDCTL_VERSION}-linux-amd64.tar.gz -C /usr/local
也可以只复制部分文件到相关目录,例如 buildctl
、 buildkitd
、containerd
、ctr
、nerdctl
、runc
等命令以及 buildkit.service
、containerd.service
文件
2.1.4 查看目录结构
$ tree
.
├── bin
│ ├── buildctl
│ ├── buildkitd
│ ├── containerd
│ ├── containerd-fuse-overlayfs-grpc
│ ├── containerd-rootless-setuptool.sh
│ ├── containerd-rootless.sh
│ ├── containerd-shim-runc-v2
│ ├── containerd-stargz-grpc
│ ├── ctd-decoder
│ ├── ctr
│ ├── ctr-enc
│ ├── ctr-remote
│ ├── fuse-overlayfs
│ ├── ipfs
│ ├── nerdctl
│ ├── rootlessctl
│ ├── rootlesskit
│ ├── runc
│ └── slirp4netns
├── lib
│ └── systemd
│ └── system
│ ├── buildkit.service
│ ├── containerd.service
│ └── stargz-snapshotter.service
├── libexec
│ └── cni
│ ├── bandwidth
│ ├── bridge
│ ├── dhcp
│ ├── firewall
│ ├── host-device
│ ├── host-local
│ ├── ipvlan
│ ├── isolation
│ ├── loopback
│ ├── macvlan
│ ├── portmap
│ ├── ptp
│ ├── sbr
│ ├── static
│ ├── tuning
│ ├── vlan
│ └── vrf
└── share
└── doc
├── nerdctl
│ ├── docs
│ │ ├── cni.md
│ │ ├── compose.md
│ │ ├── config.md
│ │ ├── cosign.md
│ │ ├── dir.md
│ │ ├── experimental.md
│ │ ├── faq.md
│ │ ├── freebsd.md
│ │ ├── gpu.md
│ │ ├── ipfs.md
│ │ ├── multi-platform.md
│ │ ├── ocicrypt.md
│ │ ├── registry.md
│ │ ├── rootless.md
│ │ └── stargz.md
│ └── README.md
└── nerdctl-full
├── README.md
└── SHA256SUMS
11 directories, 57 files
2.1.5 启动containerd与buildkit
systemctl enable containerd buildkit && systemctl start containerd buildkit
2.1.6 验证
$ ctr version
Client:
Version: v1.5.9
Revision: 1407cab509ff0d96baa4f0eb6ff9980270e6e620
Go version: go1.17.6
Server:
Version: v1.5.9
Revision: 1407cab509ff0d96baa4f0eb6ff9980270e6e620
UUID: 0fd8e6f7-ba7a-4715-844f-c8261932a201
$ nerdctl version
Client:
Version: v0.16.1
Git commit: c4bd56b3aa220db037cc6c0a4e0c8cc062f2cc4c
Server:
containerd:
Version: v1.5.9
GitCommit: 1407cab509ff0d96baa4f0eb6ff9980270e6e620
$ buildctl -v
buildctl github.com/moby/buildkit v0.9.3 8d2625494a6a3d413e3d875a2ff7dd9b1ed1b1a9
$ buildkitd -v
buildkitd github.com/moby/buildkit v0.9.3 8d2625494a6a3d413e3d875a2ff7dd9b1ed1b1a9
2.1.7 卸载containerd、nerdctl、buildkit
2.1.7.1 停止containerd与buildkit服务
systemctl disable containerd buildkit && systemctl stop containerd buildkit && systemctl status containerd buildkit
2.1.7.2 卸载containerd、nerdctl、buildkit
卸载containerd、nerdctl、buildkit删除相关目录文件即可
rm -rf /usr/local/bin/{buildctl,buildkitd,containerd,containerd-fuse-overlayfs-grpc,containerd-rootless-setuptool.sh,containerd-rootless.sh,containerd-shim-runc-v2,containerd-stargz-grpc,ctd-decoder,ctd-decoder,ctr,ctr-enc,ctr-remote,fuse-overlayfs,ipfs,nerdctl,rootlessctl,rootlesskit,runc,slirp4netns} \
/usr/local/lib/systemd/system/{buildkit.service,containerd.service,stargz-snapshotter.service} \
/usr/local/libexec/cni \
/usr/local/share/doc/{nerdctl,nerdctl-full}
2.2 已安装containerd
如果已经安装过了containerd,则直接下载 nerdctl-<VERSION\>-linux-amd64.tar.gz
2.2.1 下载包
export NERDCTL_VERSION=0.16.1
wget https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz
2.2.2 查看包内容
# 查看包内容,解压缩后是2个sh文件和nerdctl二进制命令
$ tar tf nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz
nerdctl
containerd-rootless-setuptool.sh
containerd-rootless.sh
2.2.3 解压缩包
tar xf nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz